package chain.example;

/**
 * @Author：LJ
 * @Description：
 * @Date: 2017/11/30
 * @Modified By:
 */
public abstract class Handler {
    public final static int FATHER_LEVEL_REQUEST = 1;
    public final static int HUSBAND_LEVEL_REQUEST = 2;
    public final static int SON_LEVEL_REQUEST = 3;
    //能处理的级别
    private int level = 0;
    //责任传递,一个责任人是谁
    private Handler nextHandler;
    //每个类都设置自己能处理那些请求

    public Handler(int level) {
        this.level = level;
    }

    public final void handMessage(IWoman woman) {
        if (woman.getLevel() == level) {
            response(woman);
        } else {
            if (nextHandler != null) {//判断是否有下级责任人,有就交由下一个责任人处理
                nextHandler.handMessage(woman);
            } else {
                System.out.println("无责任人可以处理");
            }
        }
    }

    //设置下一个责任人
    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    //具体责任人处理的业务
    protected abstract void response(IWoman woman);
}
